package com.adcc.loadsheet.movingdata.task;

import com.adcc.aoc.devLib.common.log.Log;
import com.adcc.loadsheet.movingdata.service.LoadsheetService;
import com.adcc.loadsheet.movingdata.util.FileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.io.File;

/**
 * Created by AN on 2020-05-04.
 */
@Component
@EnableScheduling
public class MoveLoadsheetDataTask{
    @Autowired
    private LoadsheetService service;

    @Scheduled(cron = "${baseCron}")
    private void movebaseData(){
        try{
            Log.info(MoveLoadsheetDataTask.class,"execute move base data task begin");
            service.moveStaff();
            service.moveDepartment();
            service.moveAirlines();
            service.moveAirports();
            service.updatebasetime();
            Log.info(MoveLoadsheetDataTask.class,"execute move base data task end");
        }catch (Exception ex){
            Log.error(MoveLoadsheetDataTask.class,"movebaseData() error",ex);
        }
    }

    @Scheduled(cron = "${loadsheetCron}")
    private void moveLoadsheetData(){
        try{
            Log.info(MoveLoadsheetDataTask.class,"execute move loadsheet data task begin");
            service.moveLoadsheetData();
            Log.info(MoveLoadsheetDataTask.class,"execute move loadsheet data task end");
        }catch (Exception ex){
            Log.error(MoveLoadsheetDataTask.class,"moveLoadsheetData() error",ex);
        }
    }

    @PostConstruct
    public void run(){
        try{
            Log.info(MoveLoadsheetDataTask.class,"App first move loadsheet data begin");
            service.appFirstRun();
            Log.info(MoveLoadsheetDataTask.class,"App first move loadsheet data end");
        }catch (Exception ex){
            Log.error(MoveLoadsheetDataTask.class,"run() error",ex);
        }
    }
}
